/**
 * Created by Administrator on 2016/3/21.
 */
var styleDirectives = angular.module('StyleDirectives');
styleDirectives.directive("liClassSwitch", function() {
    return {
        restrict: 'A',
        replace: 'false',
        link:function(scope,elem,attrs){
            elem.on("click",'li',function(){
           // elem.find('li').bind('click',function(){

                this.removeClass('active');
                angular.element(this).addClass('active');
            })

        }
    };
});
styleDirectives.directive("liClass", function($timeout) {
    return {
        restrict: 'A',
        replace: 'false',
        link:function(scope,elem,attrs){
            elem.on("click",function(e){
                angular.element(this).find('li').removeClass('selected');
                for(var i=0;i<e.path.length;i++){
                    if(e.path[i].localName == 'li'){
                        angular.element(e.path[i]).addClass('selected');
                        if(angular.element(e.path[i]).attr('reload')){
                            $timeout(function(){
                                angular.element(e.path[i]).removeClass('selected');
                            },2100);
                        }
                        break;
                    }
                }
            })
        }
    };
});
styleDirectives.directive("liMoreClass", function() {
    return {
        restrict: 'A',
        replace: 'false',
        scope: {
            flag: '=',
        },
        link:function(scope,elem,attrs){
            scope.$watch('flag',function(){
                if(scope.flag === false)
                    elem.find('li').removeClass('selected');
            })
            elem.on("click",function(e){
                if(scope.flag){
                    return ;
                }
                for(var i=0;i<e.path.length;i++){
                    if(e.path[i].localName == 'li'){
                        if(angular.element(e.path[i]).hasClass('selected')){
                            angular.element(e.path[i]).removeClass('selected');
                        }else{
                            angular.element(e.path[i]).addClass('selected');
                        }
                        break;
                    }
                }
            })
        }
    };
});
styleDirectives.directive("aClassSwitch", function() {
    return {
        restrict: 'A',
        replace: 'false',
        link:function(scope,elem,attrs){
            elem.on("click",function( e ){
                elem.find('a').removeClass('active');
                angular.element(e.target).addClass('active');
            })
        }
    };
});


